<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>详情页</h1>
    <div class="box">

    </div>
    <script>
        var val = location.href;
        //console.log(val)
        var reg = /id=(a-z0-9+)&/g;
        var res = reg.test(val);
        // console.log(res); //false
        var id = RegExp.$1; // 第一个子标配
        console.log(id);
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                var data = JSON.parse(xhr.responseText).data;
                console.log(data);
                for(let i=0;i<data.length;i++){
                    console.log(data[i].title);
                    str = `<h1>${data[i].title}</h1>`
                 
                    
                }
                document.querySelector('.box').innerHTML =str;
            }
        }
        xhr.open('get', `https://cnodejs.org/api/v1/topics/${id}`)
        xhr.send();

        



    </script>
</body>

</html>